package fasilkom.antz;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;

import com.golden.gamedev.GameObject;
import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.background.ImageBackground;

public class GameOver extends GameObject {
	
	Background background;
	Antz main;
	int music;
	
	public GameOver(Antz parent) {
		super(parent);
		main = parent;
	}
	
	public void initResources() {
		background = new ImageBackground(getImage("assets/gameover.png"));
		music = bsMusic.play("assets/gameover.mp3");
	}
	
	public void render(Graphics2D g) {
		background.render(g);
	}
	
	public void update(long elapsedTime){
		background.update(elapsedTime);
		keyboardControl(elapsedTime);
	}
	
	public void keyboardControl(long elapsedTime){
		if(keyPressed(KeyEvent.VK_R)){
			
			for(Sprite i : main.PLAYER_GROUP.getSprites()){
				if(i==null)
					continue;
				
				GameChar temp = (GameChar)i;
				
				if(temp.status.health > 0){
					main.dead.add(temp);
					temp.status.health = temp.status.maxHealth;
					temp.status.energy = temp.status.maxEnergy;
				}
				
				
				//i.setActive(true);
			}
			
			main.reset();
			bsMusic.stop(music);
			parent.nextGameID = Antz.STAGE_1;
			finish();
		}
		
	}

}
